import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router'

Vue.use(VueRouter)

const routes: any = {}

const reqRouter = require.context('./modules', false, /\.ts$/)
reqRouter.keys().forEach(filename => {
  const routerConfig = reqRouter(filename)
  const route = routerConfig.default || routerConfig
  routes[route.name] = route
})

function mapRoutes(routeMap: Array<string>) {
  const getters: Array<RouteConfig> = []
  routeMap.forEach((route: any) => {
    getters.push(routes[route])
  })
  return getters
}

const asyncRoutes: Array<RouteConfig> = [
  ...mapRoutes(['home', 'situationalAwareness', 'personalFiles'])
]

const constRoutes:Array<RouteConfig> = [
  {
    path: '*',
    name: '*',
    component: () => import(/* webpackChunkName: "layout" */ 'views/layout/index.vue')
  }
]

export default new VueRouter({
  mode: 'hash',
  routes: asyncRoutes.concat(constRoutes)
})
